package _nio._socket._bio;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author: huangya
 * @Date: 2021/07/03
 * @Description:
 */
public class SocketServerDemo {

    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8080);
        while(true){
            final Socket socket = serverSocket.accept();
            new Thread(){
                @Override
                public void run() {
                    InputStream inputStream = null;
                    try {
                        inputStream = socket.getInputStream();
                        byte[] bytes = new byte[512];
                        int n;
                        while((n = inputStream.read(bytes)) > 0){
                            String str = new String(bytes, 0, n);
                            System.out.println(str);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }.start();


        }
    }

}
